package ylg.com.cn.beuty.http;


import com.loopj.android.http.RequestParams;

import ylg.com.cn.beuty.config.APPURL;


/**
 * Description
 * Author by wangHaitao(a758277560@gmail.com)
 * Created  on 2015/12/1.
 * Version 1.0
 */
public class NetUtils {

    /**
     * pageSize
     */
    public static int PAGE_SIZE = 10;

    private static NetUtils single = null;

    // 静态工厂方法
    public static NetUtils getInstance() {
        if (single == null) {
            single = new NetUtils();
        }
        return single;
    }

    private void norPost(String url, RequestParams params, final NetCallBack callback, final Class classType) {
        HttpUtil.post(url, params, callback, classType);
    }

    private void norPostList(String url, RequestParams params, final NetCallBack callback, final Class classType) {
        HttpUtil.postList(url, params, callback, classType);
    }

    /**
     * 验证码
     * @param doType 1：注册，2：修改密码
     * @param phone 手机号
     * @param callback 回调
     * @param classType class
     */

    public void getCaptcha(String phone, String doType, final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        params.put("phone", phone);
        params.put("doType", doType);
        norPost(APPURL.CAPTCHA, params, callback, classType);
    }


    /**
     * 注册
     * @param userAccount
     * @param userPwd
     * @param codeNum
     * @param jobName
     * @param callback
     * @param classType
     */
    public void userRegist(String userAccount, String userPwd, String codeNum, String jobName,
                           final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        params.put("userAccount", userAccount);
        params.put("userPassword", userPwd);
        params.put("codeNum", codeNum);
        params.put("jobName", jobName);
        norPost(APPURL.REGIST, params, callback, classType);
    }

    /**
     * 修改密码
     * @param userAccount
     * @param userPassword
     * @param codeNum
     * @param jobName
     * @param callback
     * @param classType
     */
    public void upDatePwd(String userAccount, String userPassword, String codeNum, String jobName,
                           final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        params.put("userAccount", userAccount);
        params.put("userPassword", userPassword);
        params.put("codeNum", codeNum);
        params.put("jobName", jobName);
        norPost(APPURL.PASSWORD_RESET, params, callback, classType);
    }
    /**
     * 登录
     *
     * @param userAccount
     * @param userPwd
     * @param callback
     * @param classType
     */
    public void userLogin(String userAccount, String userPwd, final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        params.put("userAccount", userAccount);
        params.put("userPassword", userPwd);
        norPost(APPURL.LOGIN, params, callback, classType);
    }
    /**
     * 第三方绑定
     *
     * @param callback
     * @param classType
     */
    public void userThirdBing(String bindingAccount, String accessToken, int bindingType,final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        params.put("bindingAccount", bindingAccount);
        params.put("accessToken", accessToken);
        params.put("bindingType", bindingType+"");
        norPost(APPURL.THIRD_LOGIN, params, callback, classType);
    }

    /**
     * 第三方登录
     *
     * @param callback
     * @param classType
     */
    public void userThirdLogin(String bindingAccount, String accessToken, int bindingType,final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        params.put("bindingAccount", bindingAccount);
        params.put("accessToken", accessToken);
        params.put("bindingType", bindingType+"");
        norPost(APPURL.THIRD_LOGIN, params, callback, classType);
    }

    /**
     * 找回密码
     * @param userAccount
     * @param password
     * @param codeNum
     * @param jobName
     * @param callback
     * @param classType
     */
    public void passwordFind(String userAccount, String password, String codeNum, String jobName, final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        params.put("userAccount", userAccount);
        params.put("userPassword", password);
        params.put("codeNum", codeNum);
        params.put("jobName", jobName);
        norPost(APPURL.PASSWORD_FIND, params, callback, classType);
    }

    /**
     * 重置密码
     * @param oldPwd
     * @param newPwd
     * @param callback
     * @param classType
     */
    public void passwordReset(String oldPwd, String newPwd, final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        params.put("oldPassword", oldPwd);
        params.put("newPassword", newPwd);
        norPost(APPURL.PASSWORD_RESET, params, callback, classType);
    }

    /**
     * 推送的id
     * @param pushid
     * @param callback
     * @param classType
     */
    public void pushIdUpdate(String pushid, final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        params.put("pushToken", pushid);
        norPost(APPURL.PUSHID_UPDATE, params, callback, classType);
    }
    /**
     * 更新版本
     */
    public void chickVersion(final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        norPost(APPURL.APP_UPDATE, params, callback, classType);
    }
    /**
     * 关注接口
     *
     * */
    public void attentionUsers(String userIds,final NetCallBack callback, final Class classType){
        RequestParams params = new RequestParams();
        params.put("userIds",userIds);
        norPost(APPURL.APP_ATTENTION, params, callback, classType);
    }
    /**
     * 获取首页信息
     */
    public void getHomeInfo(final NetCallBack callback, final Class classType) {
        RequestParams params = new RequestParams();
        norPost(APPURL.HOME_INFO, params, callback, classType);
    }
}
